package com.gm.wj.controller;

import com.gm.wj.dao.UserDAO;
import com.gm.wj.entity.User;
import com.gm.wj.result.Result;
import com.gm.wj.result.ResultFactory;
import com.gm.wj.service.AdminMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Menu controller.
 *
 * @author Evan
 * @date 2019/11
 */
@RestController
@Slf4j
public class MenuController {
    @Autowired
    AdminMenuService adminMenuService;

    @GetMapping("/api/menu")
    public Result menu() {
        return ResultFactory.buildSuccessResult(adminMenuService.getMenusByCurrentUser());
    }

    @GetMapping("/api/admin/role/menu")
    public Result listAllMenus() {
        return ResultFactory.buildSuccessResult(adminMenuService.getMenusByRoleId(1));
    }

//    @PostMapping("/api/admin/role/menu")
//    public Result listAllMenus() {
//        return ResultFactory.buildSuccessResult(adminMenuService.getMenusByRoleId(1));
//    }

    @Resource
    UserDAO userDAO;

//    @PostMapping("/api/admin/user/selectTableNames")
    @PostMapping("/api/menu/selectTableNames")
    public Result selectTableNames(@RequestBody User requestUser) {
//        userService.editUser(requestUser);
        List<Map<String, Object>> maps = userDAO.selectTableNames("wj", "base table");
        System.out.println(maps);
        log.info("selectTableNames");
        log.info("maps {}",maps);

        return ResultFactory.buildSuccessResult(maps);
    }
}
